package com.peng.controller;

import com.peng.aop.LogAnnotation;
import com.peng.cache.Cache;
import com.peng.service.ArticleService;
import com.peng.vo.Result;
import com.peng.vo.params.ArticleParam;
import com.peng.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 首页
     * @param pageParams
     * @return
     */
    @PostMapping
    @LogAnnotation(module="文章",operation="获取文章列表")
    @Cache(expire = 30 * 1000,name = "listArticle")
    public Result listArticle(@RequestBody PageParams pageParams) {
 /*       List<ArticleVo> articles = articleService.listArticlesPage(pageParams);
        return Result.success(articles);*/
        return articleService.listArticle(pageParams);
    }

    /**
     * 最热文章
     * @return
     */
    @PostMapping("/hot")
    @Cache(expire = 5 * 60 * 1000,name = "hot")
    public Result hot(){
        int limit =5;
        return articleService.hotArticle(limit);
    }
    /**
     * 最新文章
     */
    @PostMapping("/new")
    public Result newArticles(){
        int limit =5;
        return articleService.newArticles(limit);
    }

    /**
     * 文档归案
     */
    @PostMapping("/listArchives")
    public Result listArchives(){
        return articleService.listArchives();
    }

    /**
     * 内容展示
     */
    @PostMapping("/view/{id}")
    public Result findArticleById(@PathVariable("id") String articleId){
        return articleService.findArticleById(articleId);
    }

    @PostMapping("/publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }
}
